<template>
  <!-- 问题：我们不知道时候能够拿到 maxnum 值，但是总归有一刻，会得到一个真正的maxnum值 -->
  <!-- 我们可以使用 watch 属性监听，来监听父组件传递过来的maxnum值 -->
  <div class="mui-numbox" data-numbox-min="1" data-numbox-max="9">
    <button class="mui-btn mui-btn-numbox-minus" type="button">-</button>
    <input class="mui-input-numbox" type="number" value="1" ref="num" @change="countChanged">
    <button class="mui-btn mui-btn-numbox-plus" type="button">+</button>
  </div>
</template>

<script>
import mui from "../../../static/lib/mui/js/mui.min.js";
export default {
  methods: {
    countChanged() {
      this.$emit("getSelectedCount", parseInt(this.$refs.num.value));
    }
  },
  mounted() {
    mui(".mui-numbox").numbox();
  },
  props: ["max"],
  watch: {
    "max": function(newVal, oldVal) {
      mui(".mui-numbox").numbox().setOption("max", newVal);
    }
  }
};
</script>

<style lang="scss" scoped>
</style>
